Home > Support > HOWTO List > QMail per-user spam filtering

Setting up Qmail Admin

This HOWTO will guide you through setting up Qmail Admin to have a per-user Spam Filtering option. It uses maildrop to handle mail delivery.

It is designed to follow on from the (excellent) Qmail Toaster guide (make sure you follow through to the Options section, and install SpamAssassin): http://www.shupp.org/toaster/

Download the latest version of maildrop and unpack it. You can grab it from: http://www.courier-mta.org/maildrop/

Then configure it with these options. Note that the uid and gid are your vpopmail uid/gid, and need to be correct otherwise it will not be able to deliver mail into the maildirs.


./configure --enable-maildrop-uid=vpopmail --enable-maildrop-gid=vchkpw
make
make install

Now you need to install (or re-install) Qmail Admin with per-user spam filtering option.

Note the --enable-spam-command must match the command you're actually going to use for spam filtering (and delivery!).


./configure --enable-help --enable-htmldir=/var/www/html --enable-cgibindir=/var/www/cgi-bin --enable-spam-modify --enable-spam-command="|/var/qmail/bin/preline /usr/local/bin/maildrop /home/vpopmail/.mailfilter"
make
make install

Create /home/vpopmail/.mailfilter. It should look something like this:


if (/^X-Spam-Flag: *YES/)
{
        `test -d Maildir/.Spam`
        if( $RETURNCODE == 1 )
        {
                `/usr/local/bin/maildirmake -f Spam Maildir`
                `echo "INBOX.Spam" >> Maildir/courierimapsubscribed`
        }
        exception {
                to "Maildir/.Spam/"
        }
        # if all else fails, do regular delivery
        exception {
                to "Maildir/"
        }
}
else
{
        exception {
                to "Maildir/"
        }
}

And fix up the permissions:


chown vpopmail:vchkpw /home/vpopmail/.mailfilter

This maildrop script will create a "Spam" directory if it doesn't exist for the user already. If it does exist, it will simply deliver the mail.It also tries to put the Spam folder into the default IMAP subscription list.

Now go to your regular Qmail Admin, login to one of your domains and edit a user.There should now be an option to enable spam filtering. Tick the box, and update the user. Try sending them some spam, and it should end up in their new Spam folder.